package org.syntaxlisp.core.element;

import lombok.Getter;

/**
 * @author HuangYijun
 * @data 2023-01-29 11:31
 **/
@Getter
public class NumberElement extends SyntaxLispElement {

    private final int numVal;

    private final boolean isInfinity;

    public NumberElement(int numVal, boolean isInfinity) {
        super(SyntaxLispElementType.NUMBER, null);
        this.numVal = numVal;
        this.isInfinity = isInfinity;
    }

    @Override
    public boolean equalsTo(SyntaxLispElement o) {
        return (isInfinity && ((NumberElement) o).isInfinity)
                ||  numVal == ((NumberElement) o).getNumVal();
    }

    @Override
    public int hashCode () {
        return numVal;
    }

    @Override
    public SyntaxLispElement copy() {
        return (new NumberElement(numVal, isInfinity)).copyMatchPropertiesAndReturn(this);
    }
}
